package wechat.base.snd;

import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import wechat.base.snd.WCApplication;
import wechat.base.snd.encoding.MsgEncoding;
import wechat.base.snd.util.ExecPost;

@SuppressWarnings("all")
public abstract class WCMessage {
  protected WCApplication application;
  
  protected MsgEncoding encoding;
  
  public WCMessage(final WCApplication application) {
    this.application = application;
    MsgEncoding _msgEncoding = new MsgEncoding();
    final Procedure1<MsgEncoding> _function = new Procedure1<MsgEncoding>() {
      public void apply(final MsgEncoding it) {
        it.setSafe("0");
        String _aGENT_ID = application.getAGENT_ID();
        it.setToAgentid(_aGENT_ID);
      }
    };
    MsgEncoding _doubleArrow = ObjectExtensions.<MsgEncoding>operator_doubleArrow(_msgEncoding, _function);
    this.encoding = _doubleArrow;
  }
  
  protected abstract void buildContents();
  
  public String send2Users(final Iterable<String> users) {
    String _xblockexpression = null;
    {
      this.encoding.setToUsers(((String[])Conversions.unwrapArray(users, String.class)));
      this.buildContents();
      String _applicationUrl = this.application.getApplicationUrl();
      String _string = this.encoding.toString();
      _xblockexpression = ExecPost.excuteJsonPost(_applicationUrl, _string);
    }
    return _xblockexpression;
  }
}
